import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { initPluginPWA } from './build/pwa-config'
const path = require('path')

function resolve(dir: string) {
  return path.join(__dirname, dir)
}
// https://vitejs.dev/config/
export default defineConfig({
  // root:"/seobench/",
  plugins: [
    vue(),
    initPluginPWA()
  ],
  resolve: {
    alias: {
      '@': resolve('./src'),
      '@database': resolve('./src/database'),
    }
  },
  server: {
    host: '0.0.0.0',
    port: 5173,
    proxy: {
      '/seobench-api/': {
        // target: 'http://www.ahzy.top:888/',
         target: 'http://localhost:9999/',
        changeOrigin: false,
      },
    },

  },
  base: '/seobench/',
  build: {
    rollupOptions: {
      output: {
        // 分包逻辑
        manualChunks(id) {
          // mdi 较大，单独拆包
          if (id.includes('@mdi')) {
            return 'mdi'
          }
          // JSON formatter 分离
          if (id.includes('node_modules/json-formatter-js')) {
            return 'json-formatter'
          }
          // 其余依赖均拆分至 libs 模块
          if (id.includes('node_modules')) {
            return 'libs'
          }
        },
      },
    },
  },
})